<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Basic usage</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="imagick.examples.html">范例</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="class.imagick.html">Imagick</a></div>
 <div class="up"><a href="imagick.examples.html">范例</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="imagick.examples-1" class="section">
  <h2 class="title">Basic usage</h2>
  <p class="para">
   Imagick makes image manipulation in PHP extremely easy through an OO
   interface. Here is a quick example on how to make a thumbnail:
   <div class="example" id="example-3209">
    <p><strong>Example #1 Creating a thumbnail in Imagick</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />header</span><span style="color: #007700">(</span><span style="color: #DD0000">'Content-type:&nbsp;image/jpeg'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$image&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">Imagick</span><span style="color: #007700">(</span><span style="color: #DD0000">'image.jpg'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;If&nbsp;0&nbsp;is&nbsp;provided&nbsp;as&nbsp;a&nbsp;width&nbsp;or&nbsp;height&nbsp;parameter,<br />//&nbsp;aspect&nbsp;ratio&nbsp;is&nbsp;maintained<br /></span><span style="color: #0000BB">$image</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">thumbnailImage</span><span style="color: #007700">(</span><span style="color: #0000BB">100</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">);<br /><br />echo&nbsp;</span><span style="color: #0000BB">$image</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>

  <p class="para">
   Using SPL and other OO features supported in Imagick, it can be simple
   to resize all files in a directory (useful for batch resizing large
   digital camera images to be web viewable). Here we use resize, as we might
   want to retain certain meta-data:
   <div class="example" id="example-3210">
    <p><strong>Example #2 Make a thumbnail of all JPG files in a directory</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$images&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">Imagick</span><span style="color: #007700">(</span><span style="color: #0000BB">glob</span><span style="color: #007700">(</span><span style="color: #DD0000">'images/*.JPG'</span><span style="color: #007700">));<br /><br />foreach(</span><span style="color: #0000BB">$images&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$image</span><span style="color: #007700">)&nbsp;{<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;Providing&nbsp;0&nbsp;forces&nbsp;thumbnailImage&nbsp;to&nbsp;maintain&nbsp;aspect&nbsp;ratio<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$image</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">thumbnailImage</span><span style="color: #007700">(</span><span style="color: #0000BB">1024</span><span style="color: #007700">,</span><span style="color: #0000BB">0</span><span style="color: #007700">);<br /><br />}<br /><br /></span><span style="color: #0000BB">$images</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">writeImages</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
  <p class="para">
   This is an example of creating a reflection of an image.
   The reflection is created by flipping the image and overlaying a gradient on it.
   Then both, the original image and the reflection is overlayed on a canvas.
   <div class="example" id="example-3211">
    <p><strong>Example #3 Creating a reflection of an image</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/*&nbsp;Read&nbsp;the&nbsp;image&nbsp;*/<br /></span><span style="color: #0000BB">$im&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">Imagick</span><span style="color: #007700">(</span><span style="color: #DD0000">"test.png"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Thumbnail&nbsp;the&nbsp;image&nbsp;*/<br /></span><span style="color: #0000BB">$im</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">thumbnailImage</span><span style="color: #007700">(</span><span style="color: #0000BB">200</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">null</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Create&nbsp;a&nbsp;border&nbsp;for&nbsp;the&nbsp;image&nbsp;*/<br /></span><span style="color: #0000BB">$im</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">borderImage</span><span style="color: #007700">(new&nbsp;</span><span style="color: #0000BB">ImagickPixel</span><span style="color: #007700">(</span><span style="color: #DD0000">"white"</span><span style="color: #007700">),&nbsp;</span><span style="color: #0000BB">5</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">5</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Clone&nbsp;the&nbsp;image&nbsp;and&nbsp;flip&nbsp;it&nbsp;*/<br /></span><span style="color: #0000BB">$reflection&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$im</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">clone</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$reflection</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">flipImage</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">/*&nbsp;Create&nbsp;gradient.&nbsp;It&nbsp;will&nbsp;be&nbsp;overlayed&nbsp;on&nbsp;the&nbsp;reflection&nbsp;*/<br /></span><span style="color: #0000BB">$gradient&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">Imagick</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">/*&nbsp;Gradient&nbsp;needs&nbsp;to&nbsp;be&nbsp;large&nbsp;enough&nbsp;for&nbsp;the&nbsp;image&nbsp;and&nbsp;the&nbsp;borders&nbsp;*/<br /></span><span style="color: #0000BB">$gradient</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">newPseudoImage</span><span style="color: #007700">(</span><span style="color: #0000BB">$reflection</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getImageWidth</span><span style="color: #007700">()&nbsp;+&nbsp;</span><span style="color: #0000BB">10</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$reflection</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getImageHeight</span><span style="color: #007700">()&nbsp;+&nbsp;</span><span style="color: #0000BB">10</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"gradient:transparent-black"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Composite&nbsp;the&nbsp;gradient&nbsp;on&nbsp;the&nbsp;reflection&nbsp;*/<br /></span><span style="color: #0000BB">$reflection</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">compositeImage</span><span style="color: #007700">(</span><span style="color: #0000BB">$gradient</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">imagick</span><span style="color: #007700">::</span><span style="color: #0000BB">COMPOSITE_OVER</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Add&nbsp;some&nbsp;opacity.&nbsp;Requires&nbsp;ImageMagick&nbsp;6.2.9&nbsp;or&nbsp;later&nbsp;*/<br /></span><span style="color: #0000BB">$reflection</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setImageOpacity</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">0.3&nbsp;</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Create&nbsp;an&nbsp;empty&nbsp;canvas&nbsp;*/<br /></span><span style="color: #0000BB">$canvas&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">Imagick</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">/*&nbsp;Canvas&nbsp;needs&nbsp;to&nbsp;be&nbsp;large&nbsp;enough&nbsp;to&nbsp;hold&nbsp;the&nbsp;both&nbsp;images&nbsp;*/<br /></span><span style="color: #0000BB">$width&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$im</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getImageWidth</span><span style="color: #007700">()&nbsp;+&nbsp;</span><span style="color: #0000BB">40</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$height&nbsp;</span><span style="color: #007700">=&nbsp;(</span><span style="color: #0000BB">$im</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getImageHeight</span><span style="color: #007700">()&nbsp;*&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">)&nbsp;+&nbsp;</span><span style="color: #0000BB">30</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$canvas</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">newImage</span><span style="color: #007700">(</span><span style="color: #0000BB">$width</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$height</span><span style="color: #007700">,&nbsp;new&nbsp;</span><span style="color: #0000BB">ImagickPixel</span><span style="color: #007700">(</span><span style="color: #DD0000">"black"</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">$canvas</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setImageFormat</span><span style="color: #007700">(</span><span style="color: #DD0000">"png"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Composite&nbsp;the&nbsp;original&nbsp;image&nbsp;and&nbsp;the&nbsp;reflection&nbsp;on&nbsp;the&nbsp;canvas&nbsp;*/<br /></span><span style="color: #0000BB">$canvas</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">compositeImage</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">imagick</span><span style="color: #007700">::</span><span style="color: #0000BB">COMPOSITE_OVER</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">20</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">10</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$canvas</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">compositeImage</span><span style="color: #007700">(</span><span style="color: #0000BB">$reflection</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">imagick</span><span style="color: #007700">::</span><span style="color: #0000BB">COMPOSITE_OVER</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">20</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$im</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getImageHeight</span><span style="color: #007700">()&nbsp;+&nbsp;</span><span style="color: #0000BB">10</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Output&nbsp;the&nbsp;image*/<br /></span><span style="color: #0000BB">header</span><span style="color: #007700">(</span><span style="color: #DD0000">"Content-Type:&nbsp;image/png"</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">$canvas</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程的输出类似于：</p></div>
    <div class="mediaobject">
     
     <div class="imageobject">
      <img src="images/c0d23d2d6769e53e24a1b3136c064577-hello_world_reflection.png" alt="Output of example : Creating a reflection of an image" width="250" height="130" />
     </div>
    </div>
   </div>
  </p>
  <p class="para">
   This example illustrates how to use fill patterns during drawing.
   <div class="example" id="example-3212">
    <p><strong>Example #4 Filling text with gradient</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">/*&nbsp;Create&nbsp;a&nbsp;new&nbsp;imagick&nbsp;object&nbsp;*/<br /></span><span style="color: #0000BB">$im&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">Imagick</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">/*&nbsp;Create&nbsp;new&nbsp;image.&nbsp;This&nbsp;will&nbsp;be&nbsp;used&nbsp;as&nbsp;fill&nbsp;pattern&nbsp;*/<br /></span><span style="color: #0000BB">$im</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">newPseudoImage</span><span style="color: #007700">(</span><span style="color: #0000BB">50</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">50</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"gradient:red-black"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Create&nbsp;imagickdraw&nbsp;object&nbsp;*/<br /></span><span style="color: #0000BB">$draw&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">ImagickDraw</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">/*&nbsp;Start&nbsp;a&nbsp;new&nbsp;pattern&nbsp;called&nbsp;"gradient"&nbsp;*/<br /></span><span style="color: #0000BB">$draw</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">pushPattern</span><span style="color: #007700">(</span><span style="color: #DD0000">'gradient'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">50</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">50</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Composite&nbsp;the&nbsp;gradient&nbsp;on&nbsp;the&nbsp;pattern&nbsp;*/<br /></span><span style="color: #0000BB">$draw</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">composite</span><span style="color: #007700">(</span><span style="color: #0000BB">Imagick</span><span style="color: #007700">::</span><span style="color: #0000BB">COMPOSITE_OVER</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">50</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">50</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$im</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Close&nbsp;the&nbsp;pattern&nbsp;*/<br /></span><span style="color: #0000BB">$draw</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">popPattern</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">/*&nbsp;Use&nbsp;the&nbsp;pattern&nbsp;called&nbsp;"gradient"&nbsp;as&nbsp;the&nbsp;fill&nbsp;*/<br /></span><span style="color: #0000BB">$draw</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setFillPatternURL</span><span style="color: #007700">(</span><span style="color: #DD0000">'#gradient'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Set&nbsp;font&nbsp;size&nbsp;to&nbsp;52&nbsp;*/<br /></span><span style="color: #0000BB">$draw</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setFontSize</span><span style="color: #007700">(</span><span style="color: #0000BB">52</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Annotate&nbsp;some&nbsp;text&nbsp;*/<br /></span><span style="color: #0000BB">$draw</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">annotation</span><span style="color: #007700">(</span><span style="color: #0000BB">20</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">50</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"Hello&nbsp;World!"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Create&nbsp;a&nbsp;new&nbsp;canvas&nbsp;object&nbsp;and&nbsp;a&nbsp;white&nbsp;image&nbsp;*/<br /></span><span style="color: #0000BB">$canvas&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">Imagick</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$canvas</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">newImage</span><span style="color: #007700">(</span><span style="color: #0000BB">350</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">70</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"white"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Draw&nbsp;the&nbsp;ImagickDraw&nbsp;on&nbsp;to&nbsp;the&nbsp;canvas&nbsp;*/<br /></span><span style="color: #0000BB">$canvas</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">drawImage</span><span style="color: #007700">(</span><span style="color: #0000BB">$draw</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;1px&nbsp;black&nbsp;border&nbsp;around&nbsp;the&nbsp;image&nbsp;*/<br /></span><span style="color: #0000BB">$canvas</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">borderImage</span><span style="color: #007700">(</span><span style="color: #DD0000">'black'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Set&nbsp;the&nbsp;format&nbsp;to&nbsp;PNG&nbsp;*/<br /></span><span style="color: #0000BB">$canvas</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setImageFormat</span><span style="color: #007700">(</span><span style="color: #DD0000">'png'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Output&nbsp;the&nbsp;image&nbsp;*/<br /></span><span style="color: #0000BB">header</span><span style="color: #007700">(</span><span style="color: #DD0000">"Content-Type:&nbsp;image/png"</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">$canvas</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程的输出类似于：</p></div>
    <div class="mediaobject">
     
     <div class="imageobject">
      <img src="images/c0d23d2d6769e53e24a1b3136c064577-hello_world.png" alt="Output of example : Filling text with gradient" width="352" height="72" />
     </div>
    </div>
   </div>
  </p>
  <p class="para">
   Working with animated GIF images
   <div class="example" id="example-3213">
    <p><strong>Example #5 Read in GIF image and resize all frames</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">/*&nbsp;Create&nbsp;a&nbsp;new&nbsp;imagick&nbsp;object&nbsp;and&nbsp;read&nbsp;in&nbsp;GIF&nbsp;*/<br /></span><span style="color: #0000BB">$im&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">Imagick</span><span style="color: #007700">(</span><span style="color: #DD0000">"example.gif"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Resize&nbsp;all&nbsp;frames&nbsp;*/<br /></span><span style="color: #007700">foreach&nbsp;(</span><span style="color: #0000BB">$im&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$frame</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/*&nbsp;50x50&nbsp;frames&nbsp;*/<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$frame</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">thumbnailImage</span><span style="color: #007700">(</span><span style="color: #0000BB">50</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">50</span><span style="color: #007700">);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/*&nbsp;Set&nbsp;the&nbsp;virtual&nbsp;canvas&nbsp;to&nbsp;correct&nbsp;size&nbsp;*/<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$frame</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setImagePage</span><span style="color: #007700">(</span><span style="color: #0000BB">50</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">50</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #FF8000">/*&nbsp;Notice&nbsp;writeImages&nbsp;instead&nbsp;of&nbsp;writeImage&nbsp;*/<br /></span><span style="color: #0000BB">$im</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">writeImages</span><span style="color: #007700">(</span><span style="color: #DD0000">"example_small.gif"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
  <p class="para">
   Working with ellipse primitive and custom fonts
   <div class="example" id="example-3214">
    <p><strong>Example #6 Create a PHP logo</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/*&nbsp;Set&nbsp;width&nbsp;and&nbsp;height&nbsp;in&nbsp;proportion&nbsp;of&nbsp;genuine&nbsp;PHP&nbsp;logo&nbsp;*/<br /></span><span style="color: #0000BB">$width&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">400</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$height&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">210</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">/*&nbsp;Create&nbsp;an&nbsp;Imagick&nbsp;object&nbsp;with&nbsp;transparent&nbsp;canvas&nbsp;*/<br /></span><span style="color: #0000BB">$img&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">Imagick</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$img</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">newImage</span><span style="color: #007700">(</span><span style="color: #0000BB">$width</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$height</span><span style="color: #007700">,&nbsp;new&nbsp;</span><span style="color: #0000BB">ImagickPixel</span><span style="color: #007700">(</span><span style="color: #DD0000">'transparent'</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">/*&nbsp;New&nbsp;ImagickDraw&nbsp;instance&nbsp;for&nbsp;ellipse&nbsp;draw&nbsp;*/<br /></span><span style="color: #0000BB">$draw&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">ImagickDraw</span><span style="color: #007700">();<br /></span><span style="color: #FF8000">/*&nbsp;Set&nbsp;purple&nbsp;fill&nbsp;color&nbsp;for&nbsp;ellipse&nbsp;*/<br /></span><span style="color: #0000BB">$draw</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setFillColor</span><span style="color: #007700">(</span><span style="color: #DD0000">'#777bb4'</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">/*&nbsp;Set&nbsp;ellipse&nbsp;dimensions&nbsp;*/<br /></span><span style="color: #0000BB">$draw</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">ellipse</span><span style="color: #007700">(</span><span style="color: #0000BB">$width&nbsp;</span><span style="color: #007700">/&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$height&nbsp;</span><span style="color: #007700">/&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$width&nbsp;</span><span style="color: #007700">/&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$height&nbsp;</span><span style="color: #007700">/&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">360</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">/*&nbsp;Draw&nbsp;ellipse&nbsp;onto&nbsp;the&nbsp;canvas&nbsp;*/<br /></span><span style="color: #0000BB">$img</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">drawImage</span><span style="color: #007700">(</span><span style="color: #0000BB">$draw</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Reset&nbsp;fill&nbsp;color&nbsp;from&nbsp;purple&nbsp;to&nbsp;black&nbsp;for&nbsp;text&nbsp;(note:&nbsp;we&nbsp;are&nbsp;reusing&nbsp;ImagickDraw&nbsp;object)&nbsp;*/<br /></span><span style="color: #0000BB">$draw</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setFillColor</span><span style="color: #007700">(</span><span style="color: #DD0000">'black'</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">/*&nbsp;Set&nbsp;stroke&nbsp;border&nbsp;to&nbsp;white&nbsp;color&nbsp;*/<br /></span><span style="color: #0000BB">$draw</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setStrokeColor</span><span style="color: #007700">(</span><span style="color: #DD0000">'white'</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">/*&nbsp;Set&nbsp;stroke&nbsp;border&nbsp;thickness&nbsp;*/<br /></span><span style="color: #0000BB">$draw</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setStrokeWidth</span><span style="color: #007700">(</span><span style="color: #0000BB">2</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">/*&nbsp;Set&nbsp;font&nbsp;kerning&nbsp;(negative&nbsp;value&nbsp;means&nbsp;that&nbsp;letters&nbsp;are&nbsp;closer&nbsp;to&nbsp;each&nbsp;other)&nbsp;*/<br /></span><span style="color: #0000BB">$draw</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setTextKerning</span><span style="color: #007700">(-</span><span style="color: #0000BB">8</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">/*&nbsp;Set&nbsp;font&nbsp;and&nbsp;font&nbsp;size&nbsp;used&nbsp;in&nbsp;PHP&nbsp;logo&nbsp;*/<br /></span><span style="color: #0000BB">$draw</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setFont</span><span style="color: #007700">(</span><span style="color: #DD0000">'Handel&nbsp;Gothic.ttf'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$draw</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setFontSize</span><span style="color: #007700">(</span><span style="color: #0000BB">150</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">/*&nbsp;Center&nbsp;text&nbsp;horizontally&nbsp;and&nbsp;vertically&nbsp;*/<br /></span><span style="color: #0000BB">$draw</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setGravity</span><span style="color: #007700">(</span><span style="color: #0000BB">Imagick</span><span style="color: #007700">::</span><span style="color: #0000BB">GRAVITY_CENTER</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Add&nbsp;center&nbsp;"php"&nbsp;with&nbsp;Y&nbsp;offset&nbsp;of&nbsp;-10&nbsp;to&nbsp;canvas&nbsp;(inside&nbsp;ellipse)&nbsp;*/<br /></span><span style="color: #0000BB">$img</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">annotateImage</span><span style="color: #007700">(</span><span style="color: #0000BB">$draw</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;-</span><span style="color: #0000BB">10</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'php'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$img</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setImageFormat</span><span style="color: #007700">(</span><span style="color: #DD0000">'png'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Set&nbsp;appropriate&nbsp;header&nbsp;for&nbsp;PNG&nbsp;and&nbsp;output&nbsp;the&nbsp;image&nbsp;*/<br /></span><span style="color: #0000BB">header</span><span style="color: #007700">(</span><span style="color: #DD0000">'Content-Type:&nbsp;image/png'</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">$img</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程的输出类似于：</p></div>
    <div class="mediaobject">
     
     <div class="imageobject">
      <img src="images/c0d23d2d6769e53e24a1b3136c064577-php_logo.png" alt="Output of example : Creating PHP logo with Imagick" width="300" height="180" />
     </div>
    </div>
   </div>
  </p>
 </div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="imagick.examples.html">范例</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="class.imagick.html">Imagick</a></div>
 <div class="up"><a href="imagick.examples.html">范例</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
